// pages/book/book.js
// const utils = require("../../utils/index")
const { http, handleStar, handleTitle } = require("../../utils/index")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        books: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var url = `http://47.108.197.28:8000/book`;
        // utils.http({
        http({
            url,
            success: res => {
                var arr = [];
                res.data.forEach(item => {
                    var { coverImage, title, rating } = item;
                    var rat = rating;
                    arr.push({
                        coverImage,
                        title:handleTitle(title),
                        // rating: utils.handleStar(rating)
                        rat,
                        rating: handleStar(rating)
                    })
                })
                this.setData({
                    books: arr
                })
            }
        })
    }
})